<?php
	function timename($ctime) {
		//时间
		$time = time() - $ctime;//当前时间离发布微博时间差
		$adate = date("Ymd", time());//当前年月日
		$ddate = date("Ymd", $ctime);//该记录年月日
		$andate = date("Y", time());//当前年
		$dndate = date("Y", $ctime);//该记录年
		
		if ($time < 60 && $adate == $ddate) {//时间差小于一分且是当天
			//true
			$tname = "刚刚";//时间名
		}elseif ($time < 3600 && $adate == $ddate) {//时间差小于一时且是当天
			//true
			$tname = intval($time / 60) . "分钟前";//时间名
		}elseif ($time < 86400 && $adate == $ddate) {//时间差小于一天且是当天
			//true
			$tname = intval($time / 3600) . "小时前";//时间名
		}elseif ($adate != $ddate) {//日期不是当天
			//true
			if ($adate == date("Ymd", $ctime + 86400)) {//日期是昨天
				//true
				$tname = "昨天&nbsp;" . date("H:i", $ctime);//时间名
			}elseif ($adate == date("Ymd", $ctime + 172800)) {//日期是前天
				//true
				$tname = "前天&nbsp;" . date("H:i", $ctime);//时间名
			}elseif ($andate == $dndate) {//日期是今年
				//true
				$tname = date("m月d日 H:i", $ctime);//时间名
			}else {
				//false
				$tname = date("Y年m月d日 H:i:s", $ctime);//时间名
			}
		}
		
		return $tname;
	}
	
	function pritname($ctime) {
		$adate = date("Ymd", time());//当前年月日
		$ddate = date("Ymd", $ctime);//该记录年月日
		$andate = date("Y", time());//当前年
		$dndate = date("Y", $ctime);//该记录年
		$zddate = date("Ymd", $ctime + 86400);//数据库昨天
		$qddate = date("Ymd", $ctime + 172800);//数据库前天
		$awdate = date("YW", time());//当前年月日周
		$dwdate = date("YW", $ctime);//该记录年月日周
		$number = array("一", "二", "三", "四", "五", "六", "日");
		
		if($adate == $ddate) {
			$tname = date("H:i", $ctime);
		}elseif($adate == $zddate) {
			$tname = "昨天&nbsp;" . date("H:i", $ctime);
		}elseif($adate == $qddate) {
			$tname = "前天&nbsp;" . date("H:i", $ctime);
		}elseif($awdate == $dwdate) {
			$tname = "星期" . $number[date("N", $ctime) - 1] . "&nbsp;" . date("H:i", $ctime);
		}elseif($andate == $dndate){
			$tname = date("m月d日 H:i", $ctime);
		}else {
			$tname = date("Y年m月d日 H:i", $ctime);
		}
		
		return $tname;
	}
?>